package com.wephone.Student.ui;

import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.text.format.Time;
import android.view.KeyEvent;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.easemob.EMCallBack;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMGroupManager;
import com.easemob.exceptions.EaseMobException;
import com.loopj.android.http.RequestParams;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.bean.SocializeEntity;
import com.umeng.socialize.bean.StatusCode;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners.SnsPostListener;
import com.umeng.socialize.media.UMImage;
import com.wephone.Student.BaseApplication;
import com.wephone.Student.R;
import com.wephone.Student.bean.BaseResponse;
import com.wephone.Student.bean.RegisterResponse;
import com.wephone.Student.network.HttpClient;
import com.wephone.Student.network.MyResponseHandler;
import com.wephone.Student.util.Constants;
import com.wephone.Student.util.MD5;
import com.wephone.Student.util.ShareReferenceUtil;
import com.wephone.Student.util.Util;

public class RegisterActivity extends BaseActivity{
	private EditText userNameEdit;
	private EditText passwordEdit;
	private EditText passwordEdit2;
	private int _year;
	private int _month;
	private int _day;
	private RadioButton genderRadio1;
	private RadioButton genderRadio2;
	private EditText nickEdit;
	private ImageView userPhoto;
	private TextView constellationsText;
	private TextView birthdayText;
	private TextView addressText;
	private Time nowTime;
	public static int uLocType=-1;
	public static String uLocDetail="";
//	private File photoTempFile = new File(Constants.IMAGE_PHOTO_TMP_PATH+"tmpPic.jpg");
	private File photoSavedFile = null;
	private String photoSavedName = null;
	private boolean hasPhotoUpload = false;
	private String uPlatform;
	private String uPlatformid;
	private ProgressDialog progressDialog;
	private String gender;
	private String username;
	private EditText signEdit;
	
	private MyResponseHandler getHandler(){
		MyResponseHandler handler = new MyResponseHandler(RegisterActivity.this,RegisterResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				

				if(progressDialog!=null){
					progressDialog.dismiss();
				}
				if(getDataSuccess){
					RegisterResponse res = (RegisterResponse)response;
					BaseActivity.infoData = res.getData();
					ShareReferenceUtil.saveUserId(getApplicationContext(), res.getData().getuId());
//					setAliasAndTags(ShareReferenceUtil.getUserId(getApplicationContext()));
					String infoJson = gson.toJson(res.getData());
					ShareReferenceUtil.saveUserInfoJson(getApplicationContext(), infoJson);
					
					if(photoSavedFile!=null && photoSavedFile.exists()){
						photoSavedFile.delete();
					}
					//reg push
					RequestParams params = new RequestParams();
					params.put("uId", BaseActivity.getMyInfo(getApplicationContext()).getuId());
					params.put("uPushIdentifier", ShareReferenceUtil.getUserPushId(getApplicationContext()));
					HttpClient.getInstance().get(Constants.API_REG_PUSH_URL, params, getHandler2());
					
					//login huanxin account
					EMChatManager.getInstance().login(infoData.getuId(), infoData.getuPwd(), new EMCallBack() {
						@Override
						public void onError(int arg0, final String errorMsg) {
							runOnUiThread(new Runnable() {
								public void run() {
									Toast.makeText(RegisterActivity.this, "登录聊天服务器失败，您将收不到消息", Toast.LENGTH_SHORT).show();
								}
							});
						}

						@Override
						public void onProgress(int arg0, String arg1) {
						}

						@Override
						public void onSuccess() {
							// 登陆成功，保存用户名密码
							BaseApplication.getInstance().setUserName(infoData.getuId());
							BaseApplication.getInstance().setPassword(infoData.getuPwd());
							runOnUiThread(new Runnable() {
								public void run() {
									EMGroupManager.getInstance().loadAllGroups();
									EMChatManager.getInstance().loadAllConversations();
										
								}
							});
							processContactsAndGroups();
//							try {
//								// demo中简单的处理成每次登陆都去获取好友username，开发者自己根据情况而定
//								List<String> usernames = EMChatManager.getInstance().getContactUserNames();
//								System.out.println("-----usernames.size()-----"+usernames.size());
//								Map<String, User> userlist = new HashMap<String, User>();
//								for (String username : usernames) {
//									User user = new User();
//									user.setUsername(username);
//									setUserHearder(username, user);
//									userlist.put(username, user);
//								}
//								// 添加user"新的朋友"
//								User newFriends = new User();
//								newFriends.setUsername(Constant.NEW_FRIENDS_USERNAME);
//								newFriends.setNick("新的朋友");
//								newFriends.setHeader("");
//								userlist.put(Constant.NEW_FRIENDS_USERNAME,newFriends);
							
							
							
//							List<String> userNameList = EMChatDB.getInstance().findAllParticipantsWithMsg();
//							for(String userName:userNameList){
//								User newFriends = new User();
//								newFriends.setUsername(userName);
//								newFriends.setNick("nick"+userName);
//								newFriends.setHeader("");
//								userlist.put(Constant.NEW_FRIENDS_USERNAME,newFriends);
//							}
							
//								//添加"群聊"
////								User groupUser = new User();
////								groupUser.setUsername(Constant.GROUP_USERNAME);
////								groupUser.setNick("群聊");
////								groupUser.setHeader("");
////								userlist.put(Constant.GROUP_USERNAME, groupUser);
//								
//								//存入内存
//								BaseApplication.getInstance().setContactList(userlist);
//								// 存入db
//								UserDao dao = new UserDao(MainActivity.this);
//								List<User> users = new ArrayList<User>(userlist.values());
//								dao.saveContactList(users);
		//
//								// 获取群聊列表,sdk会把群组存入到EMGroupManager和db中
//								EMGroupManager.getInstance().getGroupsFromServer();
//							} catch (Exception e) {
//								e.printStackTrace();
//							}
							
//							EMChat.getInstance().setAppInited();
						}
					});
					//登录分享
					UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");
					if(uPlatform!=null){
						if(uPlatform.equals("sina")){
							mController.setShareContent(Constants.LOGIN_SHARE_TEXT);
							mController.setShareMedia(new UMImage(getApplicationContext(), R.drawable.login_share_image));
							mController.directShare(getApplicationContext(), SHARE_MEDIA.SINA,new SnsPostListener() {
						            @Override
						            public void onStart() {
//						                Toast.makeText(getApplicationContext(), "分享开始",Toast.LENGTH_SHORT).show();
						            }

						            @Override
						            public void onComplete(SHARE_MEDIA platform,int eCode, SocializeEntity entity) {
						                if(eCode == StatusCode.ST_CODE_SUCCESSED){
//						                    Toast.makeText(getApplicationContext(), "分享成功",Toast.LENGTH_SHORT).show();
						                }else{
//						                    Toast.makeText(getApplicationContext(), "分享失败",Toast.LENGTH_SHORT).show();
						                }
						            }
						    });
						}
//						else if(uPlatform.equals("qq")){
//							mController.setShareContent(Constants.LOGIN_SHARE_TEXT);
//							mController.setShareMedia(new UMImage(getApplicationContext(), R.drawable.login_share_image));
//							mController.directShare(getApplicationContext(), SHARE_MEDIA.TENCENT,new SnsPostListener() {
//						            @Override
//						            public void onStart() {
////						                Toast.makeText(getApplicationContext(), "分享开始",Toast.LENGTH_SHORT).show();
//						            }
//
//						            @Override
//						            public void onComplete(SHARE_MEDIA platform,int eCode, SocializeEntity entity) {
//						                if(eCode == StatusCode.ST_CODE_SUCCESSED){
////						                    Toast.makeText(getApplicationContext(), "分享成功",Toast.LENGTH_SHORT).show();
//						                }else{
////						                    Toast.makeText(getApplicationContext(), "分享失败",Toast.LENGTH_SHORT).show();
//						                }
//						            }
//						    });
//						}else if(uPlatform.equals("weixin")){
//							mController.setShareContent(Constants.LOGIN_SHARE_TEXT);
//							mController.setShareMedia(new UMImage(getApplicationContext(), R.drawable.login_share_image));
//							mController.directShare(getApplicationContext(), SHARE_MEDIA.WEIXIN,new SnsPostListener() {
//						            @Override
//						            public void onStart() {
////						                Toast.makeText(getApplicationContext(), "分享开始",Toast.LENGTH_SHORT).show();
//						            }
//
//						            @Override
//						            public void onComplete(SHARE_MEDIA platform,int eCode, SocializeEntity entity) {
//						                if(eCode == StatusCode.ST_CODE_SUCCESSED){
////						                    Toast.makeText(getApplicationContext(), "分享成功",Toast.LENGTH_SHORT).show();
//						                }else{
////						                    Toast.makeText(getApplicationContext(), "分享失败",Toast.LENGTH_SHORT).show();
//						                }
//						            }
//						    });
//						}
					}
					
					startActivity(new Intent(getApplicationContext(),MainTabBar.class));
					finish();
				}
			}
		
			@Override
			public void onFailure(Throwable arg0, String result) {
				super.onFailure(arg0, result);
				
				if(progressDialog!=null){
					progressDialog.dismiss();
				}
				Toast.makeText(getApplicationContext(), getString(R.string.network_error_txt), Toast.LENGTH_SHORT).show();
			}
			
			
		};
		return handler;
	}
	private void processContactsAndGroups(){
		 // 获取群聊列表(群聊里只有groupid和groupname等简单信息，不包含members),sdk会把群组存入到内存和db中
	        try {
				EMGroupManager.getInstance().getGroupsFromServer();
			} catch (EaseMobException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	private MyResponseHandler getHandler2(){
		MyResponseHandler handler = new MyResponseHandler(RegisterActivity.this,BaseResponse.class){
			@Override
			public void onSuccess(String result) {
				super.onSuccess(result);
				
//				if(getDataSuccess){
//					
//				}
			}
		};
		return handler;
	}
	
//	private Handler handler = new Handler(){
//		@Override
//		public void handleMessage(Message msg) {
//			if(msg.what==11){
//				List<CountryData> results = (List<CountryData>)msg.obj;
//				countryList.clear();
//				countryList.addAll(results);
//			}
//		}
//	};
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(resultCode==111){
			//TODO
			if(uLocType==3){
				addressText.setText("我在国外");
			}else if(uLocType==1){
				addressText.setText("我在国内（海归）");
			}else if(uLocType==2){
				addressText.setText("我在国内（想要出国）");
			}
		}else if(requestCode==1){
//   	 		Uri mImageCaptureUri = data.getData();
//   	 		if(mImageCaptureUri!=null){
//	   	 		Bitmap bitmap;
//				try {
//					bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageCaptureUri);
//					if(bitmap!=null){  
//						userPhoto.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, 300, 300));
//				   	} 
//				}catch(Exception e){
//					e.printStackTrace();
//				}
//   	 		}else{
//	   	 		Bundle extras = data.getExtras();  
//				if(extras!=null){
//					Bitmap bitmap = extras.getParcelable("data");
//					if(bitmap!=null){
//						userPhoto.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, 300, 300));
//					}
//				}
//   	 		}
			if(photoSavedFile!=null && photoSavedFile.exists()){
				hasPhotoUpload = true;
				Bitmap bitmap = Util.getBitmap(getApplicationContext(),photoSavedFile.getPath(),300);
       		 	userPhoto.setImageBitmap(bitmap);
       		 	Util.saveMyBitmap(bitmap,photoSavedName,getApplicationContext());
			}else if(data!=null){
				Bundle bundle = data.getExtras();
				if(bundle!=null){
					Bitmap tmpbitmap = (Bitmap)bundle.get("data");
					if(tmpbitmap!=null){
						hasPhotoUpload = true;
						userPhoto.setImageBitmap(tmpbitmap);
		       		 	Util.saveMyBitmap(tmpbitmap,photoSavedName,getApplicationContext());
					}
				}
			}
   	 	}else if(requestCode==2){
	   	 	if(data!=null){
	   		 	Uri selectedImage = data.getData();
		        String[] filePathColumn = {MediaStore.Images.Media.DATA};
		        Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
		        cursor.moveToFirst();
		        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
		        String picturePath = cursor.getString(columnIndex);
		        cursor.close();
		        if(!TextUtils.isEmpty(picturePath)){
		        	 File userLogoFile = new File(picturePath);  
		        	 if(userLogoFile.exists()){
		        		 hasPhotoUpload = true;
		        		 Bitmap bitmap = Util.getBitmap(getApplicationContext(),picturePath,300);
		        		 userPhoto.setImageBitmap(bitmap);
		        		 Util.saveMyBitmap(bitmap,photoSavedName,getApplicationContext());
		        	 }
		         }
	   	 	}
   	 	}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_register);
		
		Bundle bundle = getIntent().getExtras();
		if(bundle!=null){
			uPlatform = bundle.getString("uPlatform");
			uPlatformid = bundle.getString("uPlatformid");
			gender = bundle.getString("gender");
			username = bundle.getString("username");
		}
		
		init();
		
//		new GetCountryListAsyncTask(getApplicationContext(), handler).execute();
	}
	
	private void init(){
		userNameEdit = (EditText)findViewById(R.id.username_edit);
		passwordEdit = (EditText)findViewById(R.id.password_edit);
		passwordEdit2 = (EditText)findViewById(R.id.password_edit2);
		genderRadio1 = (RadioButton)findViewById(R.id.gender_radio_1);
		genderRadio2 = (RadioButton)findViewById(R.id.gender_radio_2);
		nickEdit = (EditText)findViewById(R.id.nick_edit);
		userPhoto = (ImageView)findViewById(R.id.register_add_photo);
		constellationsText = (TextView)findViewById(R.id.register_constellations_text);
		birthdayText = (TextView)findViewById(R.id.register_brithday_text);
		addressText = (TextView)findViewById(R.id.register_address_text);
		signEdit = (EditText)findViewById(R.id.user_info_detail_edit_8);
		
		if(!TextUtils.isEmpty(uPlatform) && !TextUtils.isEmpty(uPlatformid)){
			String nowTime = System.currentTimeMillis()/1000+"";
			userNameEdit.setText(nowTime+"@fake.com");
			passwordEdit.setText(nowTime);
			passwordEdit2.setText(nowTime);
			if(!TextUtils.isEmpty(username)){
				nickEdit.setText(username);
			}
			if(!TextUtils.isEmpty(gender)){
				int gen = Integer.parseInt(gender);
				if(gen==0){
					genderRadio1.setChecked(true);
				}else{
					genderRadio2.setChecked(true);
				}
			}
			findViewById(R.id.reg_layout_1).setVisibility(View.GONE);
			findViewById(R.id.reg_layout_2).setVisibility(View.GONE);
			findViewById(R.id.reg_layout_3).setVisibility(View.GONE);
			findViewById(R.id.reg_layout_4).setBackgroundResource(R.drawable.bg_input_single_line);
		}
		
		nowTime = new Time("GMT+8");
		nowTime.setToNow();
		_year = nowTime.year;
		_month = nowTime.month;
		_day = nowTime.monthDay;
		
		findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(getApplicationContext(),LoginActivity.class));
				finish();
			}
		});
		findViewById(R.id.btn_finish).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(TextUtils.isEmpty(userNameEdit.getText().toString())){
					Toast.makeText(getApplicationContext(), "邮箱必须填写", Toast.LENGTH_SHORT).show();
					return;
				}else if(TextUtils.isEmpty(passwordEdit.getText().toString())){
					Toast.makeText(getApplicationContext(), "密码必须填写", Toast.LENGTH_SHORT).show();
					return;
				}else if(TextUtils.isEmpty(passwordEdit2.getText().toString())){
					Toast.makeText(getApplicationContext(), "密码确认必须填写", Toast.LENGTH_SHORT).show();
					return;
				}else if(TextUtils.isEmpty(nickEdit.getText().toString().trim())){
					Toast.makeText(getApplicationContext(), "昵称必须填写", Toast.LENGTH_SHORT).show();
					return;
				}else if(TextUtils.isEmpty(birthdayText.getText().toString())){
					Toast.makeText(getApplicationContext(), "出生年月必须选择", Toast.LENGTH_SHORT).show();
					return;
				}else if(!Util.checkEmail((userNameEdit.getText().toString()))){
					Toast.makeText(getApplicationContext(), "邮箱格式不正确", Toast.LENGTH_SHORT).show();
					return;
				}else if(!passwordEdit.getText().toString().equals(passwordEdit2.getText().toString())){
					Toast.makeText(getApplicationContext(), "两次密码输入必须相同", Toast.LENGTH_SHORT).show();
					return;
				}else if(uLocType<0 || TextUtils.isEmpty(uLocDetail)){
					Toast.makeText(getApplicationContext(), "所在位置必须选择", Toast.LENGTH_SHORT).show();
					return;
				}else if(!hasPhotoUpload || photoSavedFile==null || !photoSavedFile.exists()){
					Toast.makeText(getApplicationContext(), "头像必须上传", Toast.LENGTH_SHORT).show();
					return;
				}
				
				progressDialog = ProgressDialog.show(RegisterActivity.this, "提示", "正在提交数据...", true, false);
				
				RequestParams params = new RequestParams();
				params.put("uName", nickEdit.getText().toString());
				params.put("uEmail", userNameEdit.getText().toString());
				params.put("uPwd", MD5.md5(passwordEdit.getText().toString()));
				params.put("uSign", "暂未编辑签名");
				if(!TextUtils.isEmpty(uPlatform)){
					params.put("uPlatform", uPlatform);
				}
				if(!TextUtils.isEmpty(uPlatformid)){
					params.put("uPlatformid", uPlatformid);
				}
				if(genderRadio1.isChecked()){
					params.put("uGender", "0");
				}else{
					params.put("uGender", "1");
				}
				if(!TextUtils.isEmpty(ShareReferenceUtil.getLocationLatitude(getApplicationContext()))){
					params.put("uGpsX", ShareReferenceUtil.getLocationLatitude(getApplicationContext()));
				}
				if(!TextUtils.isEmpty(ShareReferenceUtil.getLocationLontitude(getApplicationContext()))){
					params.put("uGpsY", ShareReferenceUtil.getLocationLontitude(getApplicationContext()));
				}
				if(!TextUtils.isEmpty(birthdayText.getText().toString())){
					try{
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
						Date date = sdf.parse(_year+"-"+(_month+1)+"-"+_day);
						params.put("uBirthday", ""+date.getTime()/1000);
					}catch(Exception e){
						e.printStackTrace();
					}
					params.put("uAge", ""+(nowTime.year-_year+1));
					params.put("uConstellation", constellationsText.getText().toString());
				}
				params.put("uLocType", ""+uLocType);
				params.put("uLocDetail", uLocDetail);
				if(!TextUtils.isEmpty(signEdit.getText().toString())){
					params.put("uSign", signEdit.getText().toString());
				}
				if(hasPhotoUpload && photoSavedFile!=null && photoSavedFile.exists()){
					try {
						params.put("uIcon", photoSavedFile);
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					}
				}
				
				HttpClient.getInstance().post(Constants.API_USER_REGISTER_URL, params, getHandler());
			}
		});
		findViewById(R.id.register_address_layout).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(getApplicationContext(),SelectUserLocationsActivity.class),111);
			}
		});
		
		findViewById(R.id.choose_date_layout).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				showChooseDateDialog();
			}
		});
		
		findViewById(R.id.register_add_photo_layout).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				new AlertDialog.Builder(RegisterActivity.this).setTitle("选择头像")
				.setItems(new String[]{"拍照","相册"}, new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						if(arg1==0){
							File rootFile = new File(Constants.IMAGE_PHOTO_TMP_PATH);
							if(!rootFile.exists()){
								rootFile.mkdirs();
							}
							photoSavedName = "userlogo_"+System.currentTimeMillis()+".jpg";
							photoSavedFile = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName);
							Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
							intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photoSavedFile));
		                    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
		                    startActivityForResult(intent, 1);
						}else{
							photoSavedName = "userlogo_"+System.currentTimeMillis()+".jpg";
							photoSavedFile = new File(Constants.IMAGE_PHOTO_TMP_PATH+photoSavedName);
							Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
							startActivityForResult(i, 2);
						}
					}})
				.setNegativeButton("取消", null).show();
			}
		});
		
	}
	
	private void showChooseDateDialog(){
		new DatePickerDialog(this, new OnDateSetListener() {
            public void onDateSet(DatePicker view, int year,int monthOfYear, int dayOfMonth) {
                _year = year;
                _month = monthOfYear;
                _day = dayOfMonth;
                birthdayText.setText(_year+"年"+(_month+1)+"月"+_day+"日");
                constellationsText.setText(Util.getConstellationStr(getApplicationContext(), _month+1, _day));
            }

        }, _year, _month, _day).show();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			startActivity(new Intent(getApplicationContext(),LoginActivity.class));
			finish();
			return true; 
       }
       return super.onKeyDown(keyCode, event);
	}
	
//	private void setAliasAndTags(String alias){
//		// 检查 tag 的有效性
//		String tag = "Users";
//		// ","隔开的多个 转换成 Set
//		String[] sArray = tag.split(",");
//		Set<String> tagSet = new LinkedHashSet<String>();
//		for (String sTagItme : sArray) {
//			tagSet.add(sTagItme);
//		}
//		JPushInterface.setAliasAndTags(getApplicationContext(), alias, tagSet, this);
//	}

//	@Override
//	public void gotResult(int code, String alias, Set<String> tags) {
//		String logs ;
//		switch (code) {
//			case 0:
//				logs = "Set tag and alias success, alias = " + alias + "; tags = " + tags;
//				break;
//			
//			default:
//				logs = "Failed with errorCode = " + code + " alias = " + alias + "; tags = " + tags;
//		}
//		if(!TextUtils.isEmpty(logs)){
//			System.out.println("---gotResult---"+logs);
//		}
//	}
	
}
